package com.xumx.demo.controller;

import com.xumx.demo.customize.annotate.demo.KingMouse;
import com.xumx.demo.customize.annotate.log.MethodLog;
import com.xumx.demo.pojo.Order;
import com.xumx.demo.pojo.ResponseObject;
import com.xumx.demo.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping("/helloController")
public class HelloController {

    @Autowired
    OrderService orderService;

    @RequestMapping("/hello")
    public String hello() {
        return "Hello 1 SpringBoot!";
    }

    @RequestMapping("/add")
    public String add(@RequestBody Order order) {
        orderService.add(order);
        return "Hello 1 SpringBoot!";
    }

    @RequestMapping("/find")
    public ResponseObject<List<Order>> find(@RequestBody Order order) {
        List<Order> orders = orderService.find(order);
        return ResponseObject.success(orders);
    }

    @KingMouse(value = "123")
    @MethodLog(description = "根据Id找Order")
    @RequestMapping("/findById")
    public ResponseObject<Optional<Order>> findById(@RequestBody Order order) {
        Optional<Order> orders = orderService.findById(order);
        return ResponseObject.success(orders);
    }

}
